package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.holiday.ActivityCatMerge;
import com.yanqu.road.entity.activity.holiday.UserHolidayActivityData;
import com.yanqu.road.pb.holidayactivity.HolidayActivityProto;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class HolidayActivityPb {

    public static HolidayActivityProto.UserCatsMergeDataTemp.Builder parseUserCatsMergeDataTempBuilder(Map<Integer, ActivityCatMerge> catsInfo, UserHolidayActivityData userData) {
        HolidayActivityProto.UserCatsMergeDataTemp.Builder userDataTempBuilder = HolidayActivityProto.UserCatsMergeDataTemp.newBuilder();
        userDataTempBuilder.setActivityId(userData.getActivityId());
        userDataTempBuilder.setHasTimes(userData.getHasTimes());
        userDataTempBuilder.setProgressVal(userData.getProgressVal().longValue());
        userDataTempBuilder.setMergeScore(userData.getMergeScore().longValue());
        List<Integer> catNumList = new ArrayList<>();
        for(int i=0; i < userData.getCats().length; i++){
            catNumList.add(userData.getCats(i+1));
        }
        userDataTempBuilder.setCatsInfo(StringUtils.listToString(catNumList, ","));
        return userDataTempBuilder;
    }

    public static  HolidayActivityProto.CatMergeListTemp.Builder  parseCatMergeListMsg(int activityId, Map<Integer, ActivityCatMerge> activityCatMergeMap) {
        HolidayActivityProto.CatMergeListTemp.Builder builder =  HolidayActivityProto.CatMergeListTemp.newBuilder();
        builder.setActivityId(activityId);
        for(ActivityCatMerge cat : activityCatMergeMap.values()){
            HolidayActivityProto.CatMergeTemp.Builder catTemp = HolidayActivityProto.CatMergeTemp.newBuilder();
            catTemp.setProbably(cat.getProbably());
            catTemp.setScore(cat.getScore());
            catTemp.setWeight(cat.getWeight());
            catTemp.setMergeNum(cat.getMergeNum());
            catTemp.setLevel(cat.getLevel());
            catTemp.setDesc(cat.getDesc());
            catTemp.setName(cat.getName());
            catTemp.setIcon(cat.getIcon());
            catTemp.setActivityId(activityId);
            catTemp.setId(cat.getId());
            builder.addCatList(catTemp);
        }
        return builder;
    }
}
